 <!-- d12.php -->
   
   <?php
   $link = mysql_connect('localhost:3306', 'root', '');
   if (!$link){
   die('no connection');
   }
   $db_selected = mysql_select_db('shapes_colors', $link);
   if (!$db_selected) {
       die ('Can\'t use shapes-colors : ' . mysql_error());
   }
   
   
   $color = 'pink';
   $shape = 'triangle';
   
   if(!empty($_POST['shape']))
   {
   $shape = $_POST['shape'];
   }
   if(!empty($_POST['color']))
   {
   $color = $_POST['color'];
   }
   
   
   $sql = 'select id from colors where row_colors="'.$color.'"';
   $sql2 = 'select id from shapes where row_shapes="'.$shape.'"';
   
   $r1 = mysql_query($sql, $link);
   $r2 = mysql_query($sql2, $link);
   
   
   $var1 = mysql_fetch_row($r1);
   $var2 = mysql_fetch_row($r2);
   
   
   
   
   
           
       $sql4 = 'SELECT time, shapes_id from colors_shapes WHERE colors_id='.$var1[0];
   
       $result = mysql_query($sql4, $link);
       while ($row = mysql_fetch_assoc($result)) {
   
       
           echo $row['time'].' ';
   
           $sqlblah = 'select row_shapes from shapes where id = '.$row['shapes_id'];
           $result2 = mysql_query($sqlblah, $link);
           
           $var3 = mysql_fetch_row($result2);
           echo $color.' '.$var3[0]."\n";    
   
       }
   
   
           
       $sql4 = 'SELECT time, colors_id from colors_shapes WHERE shapes_id='.$var2[0];
       $result = mysql_query($sql4, $link);
   
       $sqlid = 'SELECT row_shapes FROM shapes WHERE id = '.$var2[0];
       $result4 = mysql_query($sqlid, $link);
       $rows = mysql_fetch_row($result4);
   
       while ($row = mysql_fetch_assoc($result)) {
   
       
   
           $sqlblah = 'select row_colors from colors where id = '.$row['colors_id'];
           $result2 = mysql_query($sqlblah, $link);
           
           $var3 = mysql_fetch_row($result2);
           
           if ($rows[0]!=$shape){
   
               echo $row['time'].' ';
               echo $var3[0]."\n";    
           }
       }
   
   
   ?>
  
